﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;

namespace Jxym.wlkc2011
{
    public partial class desclr : System.Web.UI.Page
    {
        public int index = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BinData();
            }
        }

        private void BinData()
        {
            if (Request.Params["siteName"] != null && Request.Params["m"] != null)
            {
                sitename = Request.Params["siteName"];

                classId = m = Request.Params["m"];

                if (Request.Params["id"] != null)
                {
                    Panel1.Visible = false;
                    Panel2.Visible = true;

                    LoadContent(Request.Params["id"]);
                }
                else if (Request.Params["c"] != null)
                {
                    Panel1.Visible = true;
                    Panel2.Visible = false;

                    LoadList(Request.Params["c"]);
                }
                else
                {
                    Panel1.Visible = true;
                    Panel2.Visible = false;

                    LoadList(m);
                }
            }
        }

        private void LoadList(string p)
        {
            MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

            Cms_ContentClass cccInfo = ccc.GetModel(p);

            if (cccInfo != null)
            {
                if (cccInfo.Title.Contains("学生工作首页"))
                {
                    Response.Redirect("/pt.xhtml", true);
                    return;
                }

                ClassTitle = cccInfo.Title;

                IList<Cms_ContentClass> cccList = ccc.GetList("ParentID=" + cccInfo.ID, null, "Sort", 0);

                string where = "";

                if (cccList.Count > 0)
                {
                    foreach (Cms_ContentClass cccInfo2 in cccList)
                    {
                        where += "ContentClassID=" + cccInfo2.ID + " OR ";
                    }
                    where = where.TrimEnd(" OR ".ToCharArray());
                }
                else
                {
                    where = "ContentClassID=" + p;
                }

                MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();
                AspNetPager1.RecordCount = cc.GetPageCount(where, null);
                IList<Cms_Content> ccList = cc.GetPageList(where, "ADDTIME", 2, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize);

                Repeater1.DataSource = ccList;
                Repeater1.DataBind();
            }
        }

        private void LoadContent(string p)
        {
            MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();

            Cms_Content ccInfo = cc.GetModel(p);

            if (ccInfo != null)
            {
                ClassTitle = ContentTitle = ccInfo.Title;
                ContentTitle2 = "发布时间:" + ccInfo.AddTime.ToString("yyyy-MM-dd") + "&nbsp;发布人:" + ccInfo.AddUser;
                ContentHtml = ccInfo.Html;
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BinData();
        }

        public string sitename { get; set; }
        public string m { get; set; }
        public string _id { get; set; }
        public string ContentTitle { get; set; }
        public string ContentTitle2 { get; set; }
        public string ContentHtml { get; set; }
        public string ClassTitle { get; set; }
        public string classId { get; set; }
    }
}